<?php
class Dmf_Http_Manager_Fgc
{
    /**
     * Set default options
     */
    public function setDefaultOptions(  )
    {
        
    }
    
    /**
     * Make a POST request to a server
     * 
     * @param string $url
     * @param array $data
     * @param array $options
     * @return Dmf_Http_Request 
     */
    public function post( $url, $data = array(), $options = array() )
    {
        $query_string = '';
        
        foreach( $data as $index => $value )
        {
            $query_string .= $index . '=' . $value . '&';
        }
        
        $headers = array(
            'http' => array(
                'method'  => 'POST',
                'header'  => 'Content-Type: application/x-www-form-urlencoded',
                'content' => $query_string
            )
        );
        
        $headers = stream_context_create( $headers );
        $body = @file_get_contents( $url, false, $headers );
        $info = array();
        
        foreach( $http_response_header as $header )
        {
            if ( preg_match( '/http/', strtolower( $header ) ) )
            {
                preg_match( '/[0-9]{3}/', $header, $code );

                $info['http_code'] = (int)$code['0'];
            }

            if ( preg_match( '/content\-type/', strtolower( $header ) ) )
            {
                preg_match( '/: [a-zA-Z\/]*/', $header, $type );

                $info['content_type'] = substr( $type['0'], 2, strlen( $type['0'] ) );
            }
        }
        
        return new Dmf_Http_Request( $body, $info, null );
    }
    
    /**
     * Make a GET request to a server
     * 
     * @param string $url
     * @param array $options
     * @return Dmf_Http_Request 
     */
    public function get( $url, $options = array() )
    {       
        $headers = array(
            'http' => array(
                'method'  => 'GET'
            )
        );
        
        $headers = stream_context_create( $headers );
        $body = @file_get_contents( $url, false, $headers );
        $info = array();
        
        foreach( $http_response_header as $header )
        {
            if ( preg_match( '/http/', strtolower( $header ) ) )
            {
                preg_match( '/[0-9]{3}/', $header, $code );

                $info['http_code'] = (int)$code['0'];
            }

            if ( preg_match( '/content\-type/', strtolower( $header ) ) )
            {
                preg_match( '/: [a-zA-Z\/]*/', $header, $type );

                $info['content_type'] = substr( $type['0'], 2, strlen( $type['0'] ) );
            }
        }
        
        return new Dmf_Http_Request( $body, $info, null );
    }
}